<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spd" tagdir="/WEB-INF/tags/admin/"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<spd:resources />
<title>系统管理</title>
<style type="text/css">
</style>
</head>
<body class="hold-transition login-page">

<div class="login-box">
	<div class="login-box-body">
		<div class="login-logo">
			<a href="#" style="font-family: 微软雅黑;font-weight:bold;font-size:30px;color:#aaa;">系统管理</a>
		</div>
		<!-- /.login-logo -->

		<form id="formLogin">
			<div class="form-group has-feedback">
				<input type="text" class="form-control" placeholder="用户名" name="u">
				<span class="glyphicon glyphicon glyphicon-user form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
				<input type="password" class="form-control" placeholder="密码" name="p">
				<span class="glyphicon glyphicon-lock form-control-feedback"></span>
			</div>
			<div class="form-group has-feedback">
                <input type="text" class="form-control" placeholder="验证码" name="c" style="width: 70%;float: left">
                <img id="imgCode" src="${pageContext.request.contextPath}/admin/login/code.do" style="width: 30%;border: 1px solid #ccc;height: 34px;border-left: 0;">
            </div>
			<div class="row">
				<!--
                <div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label>
                            <input type="checkbox" name="rememberMe">&nbsp;&nbsp;记住我
                        </label>
                    </div>
                </div>
                -->
                <div class="col-xs-12">
                    <button class="btn btn-primary btn-block btn-flat" id="btnLogin" data-loading-text="登陆中...">登录</button>
                </div>
            </div>
			<div class="row">
				<div class="col-xs-12" style="padding-top:10px;font-weight:bold;color:red;">
					<div id="errors"></div>
					<div id="serverMsg"></div>
				</div>
			</div>
		</form>
		<!-- /form -->

	</div>
	<!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<spd:jslibs />
	
<script type="text/javascript">
$(function(){
	$('#imgCode').on('click', function(){
		$(this).attr('src', SpdUI.contextPath + '/admin/login/code.do?rt=' + new Date().getTime());
		return false;
	});
	
	$('#formLogin').validator({
		timely: 3,
		target: '#errors',
		fields: {
			u: {
				rule: 'required;length(~20)',
				msg: '请输入用户名，不超过20个字符。'
			},
			p: {
				rule: 'required;length(6~30)',
				msg: '请输入登录密码，长度6~30个字符。'
			},
			c: {
				rule: 'required',
				msg: '请输入验证码'
			}
		},
		validation: function(el, result){
			result.isValid ? $(el).parent().removeClass('has-error') : $(el).parent().addClass('has-error');
		}
	});
	
	$('#btnLogin').on('click', function(){
		$('#serverMsg').html('');
		var $form = $('#formLogin');
		if($form.isValid()){
			SpdUI.postJSON({
				url: SpdUI.contextPath + '/admin/login.do',
				data: {
					ut: SpdUI.encryptAES(SpdUI.formToObject($form))
				},
				success: function(data, json){
					window.top.location.href = SpdUI.contextPath + '/admin/frame/main.do?rt=' + new Date().getTime();
				},
				failure: function(json, message){
					$('#imgCode').attr('src', SpdUI.contextPath + '/admin/login/code.do?rt=' + new Date().getTime());
					var message = message || '登录失败，请稍后再试！';
					$('#serverMsg').html('<span class="msg-box n-right" for="c" style=""><span role="alert" class="msg-wrap n-error"><span class="n-icon"></span><span class="n-msg">' + message + '</span></span></span>');
				}
			});
		}
		return false;
	});
});
</script>
</body>
</html>